<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateTaskUpstreamTransTable extends AbstractMigration
{
    public function up()
    {
        $this->table('task_upstream_trans', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '任务下载状态表'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('entity_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '实体id'])
            ->addColumn('from_tenant_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '来源租户id'])
            ->addColumn('from_project_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '来源项目id'])
            ->addColumn('from_task_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '来源任务id'])
            ->addColumn('to_tenant_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '目标租户id'])
            ->addColumn('to_project_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '目标项目id'])
            ->addColumn('to_task_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '目标任务id'])
            ->addColumn('status', 'char', ['default' => 'default', 'limit' => 64, 'comment' => '是否下载'])
            ->addColumn('is_unzip', 'char', ['default' => 'default', 'limit' => 32, 'comment' => '是否已解压'])
            ->addColumn('is_assemble', 'char', ['default' => 'default', 'limit' => 32, 'comment' => '是否已组装文件给下游'])
            ->addColumn('download_at', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '下载时间'])
            ->addColumn('created_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建人',])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('updated', 'integer', ['null' => false, 'limit' => 11, 'default' => 0,])
            ->addIndex(['to_tenant_id', 'from_task_id', 'to_task_id'], ['name' => 'idx_to_tenant_from_to_task', 'type' => 'unique'])
            ->save();
    }

    public function down()
    {
        $this->table('task_upstream_trans')->drop()->save();
    }
}
